package com.jjw.route.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.jjw.route.algorithm.RouteGetAlgorithm;
import com.jjw.route.to.SpotPlanTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jjw.route.entity.PoiEntity;
import com.jjw.route.service.PoiService;
import com.jjw.route.utils.PageUtils;
import com.jjw.route.utils.R;



/**
 * 
 *
 * @author jjw
 * @email 2371671097@qq.com
 * @date 2023-05-12 07:45:21
 */
@RestController
@RequestMapping("route/poi")
@CrossOrigin
public class PoiController {
    @Autowired
    private PoiService poiService;
    @Autowired
    private RouteGetAlgorithm routeGetAlgorithm;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("route:poi:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = poiService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("route:poi:info")
    public R info(@PathVariable("id") Integer id){
		PoiEntity poi = poiService.getById(id);

        return R.ok().put("poi", poi);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("route:poi:save")
    public R save(@RequestBody PoiEntity poi){
		poiService.save(poi);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("route:poi:update")
    public R update(@RequestBody PoiEntity poi){
		poiService.updateById(poi);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("route:poi:delete")
    public R delete(@RequestBody Integer[] ids){
		poiService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    // 获取顶部轮播图
    @GetMapping("/topPoi")
    public R getTopPoi() {
        List<PoiEntity> topPoi = poiService.getTopPoi();
        return R.ok().put("data",topPoi);
    }

    // 获取流行度排行榜信息
    @GetMapping("/rankList")
    public R getRankList(){
        return R.ok().put("list",poiService.getPrevalenceRank());
    }

    // 获取所有景点信息
    @GetMapping("/allPoi")
    public R getAllPoi() {
        return R.ok().put("pois",poiService.getAllPoi());
    }

    @PostMapping("/getPlan")
    public R getPlan(@RequestBody SpotPlanTo spotPlanTo) {
        return R.ok().put("data",routeGetAlgorithm.getPlan(spotPlanTo));
    }
}
